/**
 * Created by Administrator on 2017/9/12.
 */

let schedule = require('node-schedule');
let slotMachine = require('./slotMachine.js');
let log = require('../util/log.js');

let cron = module.exports;

cron.init = function () {
    // 建立一个时间循环的默认规则
    //let rule = new schedule.RecurrenceRule();
    // 增加一个每秒执行的内容
    //let times = [];
    //for (let i = 1; i < 60; i++) {
    //    times.push(i);
    //}
    //rule.second = times;
    // 开始动作
    //schedule.scheduleJob('*/5 * * * * *', function () {
    // console.log('mem.slotMachinePlayers',mem.slotMachinePlayers);
    //});
    //schedule.scheduleJob('*/5 * * * * *', function () {
    //if (!slotMachine.job) {
    //    cron.slotMachineStart();
    //} else {
    //    cron.slotMachineStop();
    //}
    //});
    cron.slotMachineStart();
};
cron.slotMachineStart = function () {
    slotMachine.job = schedule.scheduleJob('0 0 * * * *', function () {
        slotMachine.setNextTime(new Date(slotMachine.job.nextInvocation()).getTime());
        slotMachine.settlement();
    });
    log.p('slotMachineStart');
    slotMachine.setNextTime(new Date(slotMachine.job.nextInvocation()).getTime());
};
cron.slotMachineStop = function () {
    slotMachine.job.cancel();
    slotMachine.job = null;
    log.p('slotMachineStop');
};